package priv.pront.code.national.acwing.base;

import java.util.Scanner;

public class 全排列1 {
    static int n;
    static int[] a;
    static boolean[] vi;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        vi = new boolean[n];
        a = new int[n];
        dfs(0);
    }

    private static void dfs(int si) {
        if (si == n) {
            for (int i : a) System.out.print(i + " ");
            System.out.println();
            return;
        }
        for (int i = 0; i < n; i++) {
            if (!vi[i]) {
                a[si] = i + 1;
                vi[i] = true;
                dfs(si + 1);
                vi[i] = false;
            }
        }
    }
}
